home *** CD-ROM | disk | FTP | other *** search
- //: C19:stringConv.h
- // From Thinking in C++, 2nd Edition
- // Available at http://www.BruceEckel.com
- // (c) Bruce Eckel 1999
- // Copyright notice in Copyright.txt
- // Chuck Allison's string converter
- #ifndef STRINGCONV_H
- #define STRINGCONV_H
- #include <string>
- #include <sstream>
-
- template<typename T>
- T fromString(const std::string& s) {
- std::istringstream is(s);
- T t;
- is >> t;
- return t;
- }
-
- template<typename T>
- std::string toString(const T& t) {
- std::ostringstream s;
- s << t;
- return s.str();
- }
- #endif // STRINGCONV_H ///:~
-